﻿using Admin.Service.RoleMenus;
using Admin.Service.RoleMenus.DTO;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleMenuController : ControllerBase
    {
        private readonly IRoleMenuService roleMenuService;

        public RoleMenuController(IRoleMenuService roleMenuService)
        {
            this.roleMenuService = roleMenuService;
        }

        /// <summary>
        /// 分配角色
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult AddRoleMenu(AddRoleMenuDto dto)
        {
            return Ok(roleMenuService.AddRoleMenu(dto));
        }

        /// <summary>
        /// 分配角色反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult FillRoleMenu(int id)
        {
            return Ok(roleMenuService.FillRoleMenu(id));
        }

        /// <summary>
        /// 权限反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult FillId(int id)
        {
            return Ok(roleMenuService.FillRoleMenu(id));
        }
    }
}
